﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
using EvaluationSystem.DAO;


namespace EvaluationSystem
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void btnLogin_Click(object sender, DirectEventArgs e)
        {
            string username = this.txtUsername.Text;
            string password = this.txtPassword.Text;
            LoginManager login = new LoginManager(username, password);
            bool loginSuccess = login.DoLogin(this.Page);
            if (loginSuccess)
            {
                lbMessage.Text = "";
                Roles role = Utility.Role(Page);
                if (role == Roles.文员 || role == Roles.系统管理员)
                {
                    Response.Redirect("ConfigurationPages/ConfigurationPage.aspx");
                }
                else if (role == Roles.None)
                {
                    X.MessageBox.Alert(Constants.Noticfy, "角色读取出错，请与开发人员联系.");
                }
                else
                {
                    Response.Redirect("EvaluationPage.aspx");
                }
            }
            else
            {
                lbMessage.Text = "用户名或密码错误，请重试.";
            }
        }
    }
}